function[Xlag,Xlag1,X_ad]=lag_variable(X,p)
% Viet Hoang Dinh
% Monash University
% Edited December 2024
%%
T=size(X,1);
Xlag=ones(T-p,1);
    for ip = 0:p-1
        Xlag = [Xlag X(p-ip:end-ip-1,:)];                                    
    end
Xlag1=Xlag;          %Lags of Xt with constant 1
Xlag=Xlag1(:,2:end); %Lags of Xt without constant 1
X_ad=X(1+p:end,:);   %Xt after adjusting n.o observations
end